﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CuaHangMayTinh.DataAccessLayer;
using CuaHangMayTinh.BusinessEntities;
using System.Data;
using CuaHangMayTinh.Utilities;

namespace CuaHangMayTinh.BusinessLogicLayer
{
    /// <summary>
    /// 
    /// </summary>
    public class BaoHanhSuaChuaManager
    {
        private static BaoHanhSuaChuaDA adapter = null;

        static BaoHanhSuaChuaManager()
        {
            if (adapter == null)
                adapter = new BaoHanhSuaChuaDA();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int Insert(BaoHanhSuaChuaEntity entity)
        {
            try
            {
                return adapter.Insert(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int InsertTS(BaoHanhSuaChuaEntity entity)
        {
            try
            {
                return adapter.InsertTS(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static int InsertTS(BaoHanhSuaChuaEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.InsertTS(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool Update_DaTraHang(BaoHanhSuaChuaEntity entity)
        {
            try
            {
                return adapter.Update_DaTraHang(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_All(bool View)
        {
            try
            {
                return adapter.Find_All(View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static DataTable GetMaHDMax()
        {
            try
            {
                return adapter.GetMaHDMax();
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static MatHangEntity GetMatHang(int MaBHSC)
        {
            try
            {
                return MatHangManager.ConvertToList(adapter.GetMatHang(MaBHSC))[0];
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="MaBHSC"></param>
        /// <returns></returns>
        public static DataTable GetInfoHoaDon(int MaBHSC)
        {
            try
            {
                return adapter.GetInfoHoaDon(MaBHSC);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        public static BaoHanhSuaChuaEntity GetAllInfo_ID(int MaBaoHanhSuaChua)
        {
            try
            {
                return adapter.GetAllInfo_ID(MaBaoHanhSuaChua);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static List<BaoHanhSuaChuaEntity> ConvertToList(DataTable dt)
        {
            try
            {
                return adapter.ConvertToList(dt);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }
    }
}

